(function() {
  app.directive('dirFooter', function() {
    return {
      restrict: 'E',
      templateUrl: 'public/directive/footer.html',
      replace: true,
      scope: {},
      controller: function($scope, $state, footer_config, getPhoneType) {
        $scope.ctrl = footer_config;
        $scope.go_to = function(url, params) {
          if (!url) return;
          $state.go(url, params ? params : undefined);
        };

        if (getPhoneType.config.type === 'iphonex') {
          footer_config.config.theme.marginBottom = getPhoneType.config.css.height;
          footer_config.config.padding_bottom = parseFloat(getPhoneType.config.css.height.split('r')[0]) + parseFloat(footer_config.config.theme.height.split('r')[0]) + 0.3 + 'rem';

        }
      },

      link: function(scope, ele, atr) {
        angular.element('body').css('padding-bottom', scope.ctrl.config.padding_bottom);
      }

    };
  });

  app.factory('footer_m', function($window, footer_config) {
    return {
      change: function(url) { // 路由改变时触发的函数
        var that = footer_config;
        that.config.show.toggle = false;
        for (var o = 0; o < that.config.show.page.length; o++) {
          if (that.config.show.page[o] === url) {
            that.config.show.toggle = true;
          }
        }

        for (var i = 0; i < that.arr.length; i++) {
          that.arr[i].actived = false;
          for (var j = 0; j < that.arr[i].show.length; j++) {
            if (that.arr[i].show[j] === url) {
              that.arr[i].actived = true;
            }
          }
        }
      }
    };
  });
})();